<?php

get_header(); // Loads the header.php template. ?>		
		
		<div id="main" class="clearfix">				
			
			<div class="center">			
				<div id="content" class="clearfix">
					<div id="top-story" class="clearfix">				
						<h2 class="top-story-title clearfix"><?php echo $cv_option['announcement']; ?></h2>
						<?php 
						$i = 0;
						//$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
						$args = array(	
							'posts_per_page' => $cv_option['topstory_amount'],
							'meta_query' => array(
								array(
									'key' => 'is_topstory',
									'value' => 'on',
									'compare' => 'LIKE')								
							)
						);
						query_posts($args);
						if(have_posts()) : while (have_posts()) : the_post(); $i++?>							
							<div class="hentry clearfix <?php if($i==2) {echo 'right'; $i=0;}?>">
								
								<div class="entry-img">
									<?php if ( current_theme_supports( 'get-the-image' ) ) {	?>									
										<?php $thumb2 = get_the_image( array( 'format' => 'array', 'echo' => false, 'custom_key' => array( 'Thumbnail', 'thumbnail' ), 'default_size' => 'topstory-image-thumb' ) ); ?>
										<?php if(!empty($thumb2['src'])) { ?>
											<a href="<?php echo esc_url(get_permalink());?>"></a>
											<strong></strong>
											<img src="<?php echo $thumb2['src'];?>">									
										<?php } 
										else { ?>
												<a href="<?php echo esc_url(get_permalink());?>"></a>
												<strong></strong>
												<img src="<?php echo get_bloginfo('template_directory').'/images/'.'topstory-no-pic.jpg'; ?>">
										<?php } 
									} ?>						
								</div><!-- .hentry-img -->
								
								<span class="entry-category">
									
									<?php
									//Get all terms associated with post in taxonomy 'category'
									$terms = get_the_terms(get_the_ID(),'category');
									
									//Get an array of their IDs
									$term_ids = wp_list_pluck($terms,'term_id');

									//Get array of parents - 0 is not a parent
									$parents = array_filter(wp_list_pluck($terms,'parent'));

									//Get array of IDs of terms which are not parents.
									$term_ids_not_parents = array_diff($term_ids,  $parents);

									//Get corresponding term objects
									$terms_not_parents = array_intersect_key($terms,  $term_ids_not_parents);
									//echo $terms_not_parents; 
									
									foreach($terms_not_parents as $t) {										
									?>
										<a href="<?php echo get_term_link($t->slug, 'category');?>"><?php echo $t->name;?></a>
									<?php } ?>
								</span><!-- .entry-category -->
								
								<?php echo apply_atomic_shortcode( 'entry_title', '[entry-title]' ); ?>		
							
							</div><!-- .hentry -->
							<?php endwhile; ?>						
							<?php endif; ?>
							<?php wp_reset_query(); 
						?>	
					</div>	<!-- .top-story -->
					
					<?php if ( have_posts() ) : 
						global $hentry_count;$hentry_count = 0;
						while ( have_posts() ) : the_post(); 					
							$hentry_count++;
							get_template_part('entry');
								
							endwhile;								

					else :
						get_template_part('no-results'); 		
					endif; ?>
						
				</div> <!-- #content -->		
			
				<?php get_sidebar( 'primary' );  ?>			
				<div class="clear"></div>
				<div id="nav-below" class="page_navi">						 
					<?php cv_pagenavi(); ?> 
				</div><!-- #nav-below -->
			</div><!-- .center -->
			
		</div><!-- #main -->		
	
	
<?php get_footer(); // Loads the footer.php template. ?>		